<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : score.manage.php   FILE_PATH : D:\webroot\mulitishop\system\score.manage.php
 * ....评价后台管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Wed Oct 24 18:54:03 CST 2007
 */

require_once("../global.inc.php");

class SysScoreManage extends SystemFrameWork{
	/**
	 * 评价对象
	 *
	 * @var obj
	 */
	var $obj_score;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 商品订单对象
	 *
	 * @var obj
	 */
	var $obj_product_order;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	

	function main(){
		/**
		 * 创建评价对象
		 */
		if (!is_object($this->obj_score)){
			require_once("score.class.php");
			$this->obj_score = new ScoreClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 创建分页对象
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}

		/**
		 * 语言包
		 */
		$this->getlang("product");

		switch($this->_input['action']){
			case "add":
				$this->_addScore();
				break;
			case "modi":
				$this->_modiScore();
				break;
			case "modisave":
				$this->_modisaveScore();
				break;
			case "dele":
				$this->_deleScore();
				break;
			default:
				$this->_getScore();
		}
	}

	/**
	 * 得到评价列表
	 *
	 */
	function _getScore(){
		$this->obj_page->pagebarnum(20);    //每页20条记录
		$score_array = $this->obj_score->getAllScore($this->_input,$this->obj_page);
		//print_r($score_array);
		$this->output('score_array',$score_array);
		$this->output('slcScore',Common::showForm_Select("score","","",$this->_b_config['grade_score'],$this->_input['score'],array('value'=>'','text'=>'请选择')));
		$this->output('slcGenre',Common::showForm_Select("genre","","",$this->_b_config['grade_genre'],$this->_input['genre'],array('value'=>'','text'=>'请选择')));
		
		$pagelist = $this->obj_page->show(1);      //分页显示
		$this->output('pagelist',$pagelist);
		$this->showpage('sys_score.manage');
	}

	/**
	 * 修改评价
	 *
	 */
	function _modiScore(){
		$score_array = $this->obj_score->getOneScore($this->_input['scoreid']);  //得到评价信息



		/**
		 * 创建商品订单对象
		 */
		if (!is_object($this->obj_product_order)){
			require_once("order.class.php");
			$this->obj_product_order = new ProductOrderClass();
		}
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new Member();
		}

		$member_array = $this->obj_member->getMemberInfo($score_array['member_id'],"1"); //评价人信息
		$grade_member_array = $this->obj_member->getMemberInfo($score_array['grade_member_id'],"1"); //被评价人信息

		$score_array['membername'] = $member_array['login_name'];

		$score_array['grademembername'] = $grade_member_array['login_name'];

		$order_array = $this->obj_product_order->getOneOrder($score_array['order_id']);  //得到订单信息

		$this->output('rdoScore',Common::showForm_Radio("score","",$this->_b_config['grade_score'],$score_array['score']));  //评分单选框

		$this->output("order_array",$order_array);
		$this->output("score_array",$score_array);
		$this->showpage('sys_score.modi');
	}

	/**
	 * 保存修改的评价信息
	 *
	 */
	function _modisaveScore(){
		/**
		 * 验证参数
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["score_id"],"require"=>"true","message"=>"错误的地址"),
		array("input"=>$this->_input["genre"],"require"=>"true","message"=>"错误的地址"),
		);

		$error = $this->objvalidate->validate();
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new Member();
		}
		if ($error == ""){
			//修改评价信息
			$this->obj_score->updateScore($this->_input,"1");
			//修改被评价人信息
			$this->obj_member->updateMemberScore($this->_input['genre'],$this->_input['score'] - $this->_input['oldscore'],$this->_input['gradememberid']);
		}else{
			echo $error;
		}
	}

	/**
	 * 删除评价
	 *
	 */
	function _deleScore(){
		$score_array = $this->obj_score->getOneScore($this->_input['scoreid']);  //得到评价信息
		$this->obj_score->deleScore($this->_input['scoreid']); //删除评价信息
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new Member();
		}
		//修改被评价人信息
		$this->obj_member->updateMemberScore($score_array['genre'],0-$score_array['score'],$score_array['grade_member_id']);
	}
}

$score_manage = new SysScoreManage();
$score_manage->main();
unset($score_manage);
?>